package com.kukudb.asaproject.aimodel.config;


import com.kukudb.asaproject.aimodel.chatServer.ToolsService;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static dev.langchain4j.data.message.SystemMessage.systemMessage;

@Configuration
public class AiConfig {

    private static final String SYSTEM_PROMPT = SystemPromptWords.SYSTEM_PROMPT_WORDS;

    public interface Assistant{
        String chat(String message);

    }

    @Bean
    public Assistant assistant(ChatLanguageModel qwenChatMdel,
                               ToolsService toolsService
                               ){
        ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(100);
        chatMemory.add(systemMessage(SYSTEM_PROMPT));
        return AiServices.builder(Assistant.class)
                .tools(toolsService)
                .chatLanguageModel(qwenChatMdel)
                .chatMemory(chatMemory)
                .build();
    }

}
